package com.example.danangtravel.Hotel;

import java.io.IOException;

import com.exam.danangtranel.filed.ATM;
import com.exam.danangtranel.filed.Hotel;
import com.example.danangtravel.DataAccess;
import com.example.danangtravel.R;
import com.example.danangtravel.allMethod;
import com.example.danangtravel.checknetwork;
import com.example.danangtravel.map.RoutePath;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;

public class HotelDetailActivity extends Activity {
	private Hotel data;
	private TextView tvDHotel, AddressDHotel, PhoneDHotel, InfDHotel;
	private allMethod getimage;
	private ImageView imgDHotel;
	private ImageButton btn_hDHotel;
	private ImageButton map_hotel;
	private checknetwork checknet;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_hoteldetail);
		Bundle extras = getIntent().getExtras();

		getimage = new allMethod(this);
		int ID = extras.getInt("ID");

		try {
			data = new DataAccess(this).getObjHotel(ID);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tvDHotel = (TextView) findViewById(R.id.tvDHotel);
		tvDHotel.setText(data.getName().toString());

		imgDHotel = (ImageView) findViewById(R.id.imgDHotel);
		try {
			imgDHotel.setImageBitmap(getimage.getimg(data.getImage()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		AddressDHotel = (TextView) findViewById(R.id.AddressDHotel);
		AddressDHotel.setText(data.getAdrress().toString());

		PhoneDHotel = (TextView) findViewById(R.id.PhoneDHotel);
		PhoneDHotel.setText(data.getPhone().toString());

		InfDHotel = (TextView) findViewById(R.id.InfDHotel);
		InfDHotel.setText(data.getInformation().toString());

		btn_hDHotel = (ImageButton) findViewById(R.id.btn_hDHotel);
		btn_hDHotel.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				finish();

			}
		});
		map_hotel = (ImageButton) findViewById(R.id.btnMapHotel);
		map_hotel.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				checknet = new checknetwork(v.getContext());
				if (checknet.isOnline()) {

					Intent i = new Intent(v.getContext(), RoutePath.class);
					i.putExtra("latitude", data.getLongitude()); // bi dao?
																	// nguoc...
					i.putExtra("longitude", data.getLatitude()); // bi dao?
																	// nguoc...
					v.getContext().startActivity(i);
				} else
					Toast.makeText(v.getContext(), "Không có kết nối !", 1000)
							.show();
			}
		});
	}
}
